package hjt.com.module_test.activity;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import android.util.SparseArray;
import android.widget.TextView;

import com.tong.lib.base.BaseActivity;
import com.tong.lib.utils.MessageEvent;
import com.tong.lib.view.PagerSlidingTabStrip;

import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import hjt.com.module_test.R;
import hjt.com.module_test.R2;
import hjt.com.module_test.fragment.TestFragment;
import hjt.com.module_test.widget.CustomScrollView;

public class ScrollActivity extends BaseActivity {

    @BindView(R2.id.tab)
    PagerSlidingTabStrip tab;
    @BindView(R2.id.vp)
    ViewPager vp;
    @BindView(R2.id.tv_video)
    TextView tvVideo;
    @BindView(R2.id.csv)
    CustomScrollView csv;

    private List<String> dataList = new ArrayList<>();
    private SparseArray<Fragment> fragmentList = new SparseArray<>();

    private boolean isPlaying = true;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_scroll;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        fragmentList.put(0, new TestFragment());
//        fragmentList.put(1, new TestFragment());
//        fragmentList.put(2, (Fragment) ARouter.getInstance()
//                .build(ARouterConstants.FRAGMENT_DESIGN_DESIGN)
//                .navigation());
        vp.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int i) {
                return fragmentList.get(i);
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return "标题" + position;
            }
        });
        tab.setViewPager(vp);

    }

    @Override
    protected void initEvent() {

        tvVideo.setOnClickListener((v) -> {
            isPlaying = !isPlaying;
            csv.setPlaying(isPlaying);
            show(isPlaying + "");
        });

    }

    @Subscribe
    public void MyEvent(MessageEvent event) {
        if (event.getMsg().equals("canMove")) {
            csv.setCanMove(true);
        }
    }

    @Override
    protected boolean isUseEventBus() {
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
